package com.goddess.yeecolor.view;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.goddess.yeecolor.R;

/**
 * 取消报名
 */
public class PopPopuWindowUtils extends PopupWindow{

    private View mView;
    public TextView popuwindow_examine,popuwindow_cancalenroll,popuwindow_cancal;

    /**
     *
     * @param context 上下文
     * @param itemsOnClick 点击事件
     * @param title  弹框的第一个文本
     * @param title1 弹框的第二个文本
     */
    public PopPopuWindowUtils(Activity context,View.OnClickListener itemsOnClick,String title,String title1,int tag){

        mView= LayoutInflater.from(context).inflate(R.layout.cancel_enroll,null);

        popuwindow_cancal= (TextView) mView.findViewById(R.id.popuwindow_cancal);
        popuwindow_examine= (TextView) mView.findViewById(R.id.popuwindow_examine);
        popuwindow_cancalenroll= (TextView) mView.findViewById(R.id.popuwindow_cancalenroll);
        popuwindow_cancal.setOnClickListener(itemsOnClick);
        popuwindow_cancalenroll.setOnClickListener(itemsOnClick);
        popuwindow_examine.setOnClickListener(itemsOnClick);
        popuwindow_examine.setText(title);
        popuwindow_cancalenroll.setText(title1);

        popuwindow_examine.setTextColor(context.getResources().getColor(R.color.purple));


        //设置SelectPicPopupWindow的View
        this.setContentView(mView);
        //设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        //设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.take_photo_anim);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
        //显示位置

        //mMenuView添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
        mView.setOnTouchListener(( v, event)->{
            int height = mView.findViewById(R.id.pop_layout).getTop();
            int y=(int) event.getY();
            if(event.getAction()==MotionEvent.ACTION_UP){
                if(y<height){
                    dismiss();
                }
            }
            return true;

        });
        //取消按钮
        popuwindow_cancal.setOnClickListener((v)->{
            //销毁弹出框
            dismiss();

        });
    }

}
